package 算法回顾;

import java.util.*;

/**
 * @author : K k
 * @date : 20:05 2020/9/6
 */
public class demo1 {

    public static void main(String[] args) {
        

        Scanner sc = new Scanner(System.in);
        Node l1=new Node(0),l2=new Node(0);
        Node tmp1=l1,tmp2=l2;
        int n1 = sc.nextInt();

        for (int i=0;i< n1;i++){
           int x=sc.nextInt();
           tmp1.next=new Node(x);
           tmp1=tmp1.next;
        }
        int n2=sc.nextInt();
        for (int i=0;i< n2;i++){
            int x=sc.nextInt();
            tmp2.next=new Node(x);
            tmp2=tmp2.next;
        }

        if (n1>=n2){
            for (Integer i :
                    conString(l1.next, l2.next)) {
                System.out.print(i+" ");
            }
        }else {
            for (Integer i :
                    conString(l2.next, l1.next)) {
                System.out.print(i+" ");
            }
        }
    }


    public static List<Integer> conString(Node n1,Node n2){
        if (n1==null || n2==null){
            return null;
        }
        Set<Integer> set=new HashSet<>();
        List<Integer> list=new ArrayList<>();
        Node tmp1=n1;
        Node tmp2=n2;
        while (tmp1!=null ){
            set.add(tmp1.val);
            tmp1=tmp1.next;
        }
        while (tmp2!=null){
            if (set.contains(tmp2.val)){
                list.add(tmp2.val);
            }
            tmp2=tmp2.next;
        }
        return list;
    }

}
class Node{
    int val;
    Node next;
    public Node(int val){
        this.val=val;
    }
}
